package cn.smile.utils;

import cn.smile.bean.form.log.log.LogAddForm;
import cn.smile.business.log.ILogInfoService;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;

/**
 * @author smile-jt
 */
@Slf4j
public class LogAddUtil {

    /**
     * 添加拦截器访问记录
     *
     * @param ip        访问ID
     * @param uri       访问URI
     * @param sessionId 用户sessionId
     */
    public static void addAccessInfo(String ip, String uri, String sessionId, boolean allow, ILogInfoService logService) {
        LogAddForm form = new LogAddForm();
        form.setUri(uri);
        form.setAccessIp(ip);
        form.setSessionId(sessionId);
        form.setUserId(UserUtil.getUserInfo().getId());
        form.setAccessTime(LocalDateTime.now());
        form.setReject(!allow);
        Boolean result = logService.addInfo(form);
        log.info("[LogAddUtil].[addAccessInfo] ------> Add End, result = {}", result);
    }
}
